package io.renren.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.entity.SysMessageAdministrationEntity;
import io.renren.service.SysMessageAdministrationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Map;


/**
 *
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2021-01-31 08:31:45
 */
@RestController
@RequestMapping("api/sysmessageadministration")
public class SysMessageAdministrationController {
    @Autowired
    private SysMessageAdministrationService sysMessageAdministrationService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = sysMessageAdministrationService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
        SysMessageAdministrationEntity sysMessageAdministration = sysMessageAdministrationService.getById(id);

        return R.ok().put("sysMessageAdministration", sysMessageAdministration);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody SysMessageAdministrationEntity sysMessageAdministration){
        sysMessageAdministration.setCreatTime(new Date());
        sysMessageAdministrationService.save(sysMessageAdministration);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SysMessageAdministrationEntity sysMessageAdministration){
        ValidatorUtils.validateEntity(sysMessageAdministration);
        sysMessageAdministrationService.updateById(sysMessageAdministration);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestParam Long id){
        sysMessageAdministrationService.removeById(id);

        return R.ok();
    }

}
